package java_thinking.unit_21._21_16;

/**
 * @Desc:   16.1 如果在程序中没有包含足够的同步，那么可能产生奇怪的结果 不要这么做
 * @author: cww
 * @DateTime: 2019-06-30 18:07
 */

public class PossibleReordering {
    static int x = 0, y = 0;
    static int a = 0, b = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread one = new Thread(new Runnable() {
            @Override
            public void run() {
                a = 1;
                x = b;
            }
        });

        Thread other = new Thread(new Runnable() {
            @Override
            public void run() {
                b = 1;
                y = a;
            }
        });
        one.start();
        other.start();
        one.join();
        other.join();
        System.out.println("(" + x + "," + y + ")");
    }

}
/**
 * 执行结果可能为(0,1)、(1,0)、(0,0)
 */